import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        // 标签页
        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index'
        }],
        // 是否绑定过路由
        hasRoute: false,
        // 菜单列表
        menuList: [],
        // 权限列表
        permList: []
    },
    mutations: {
        // 添加标签
        addTab(state, tab) {
            // 判断标签名是否重复
            let index = state.editableTabs.findIndex(current => current.name ===  tab.name)

            //当前标签未存在，就进行新增
            if(index === -1){
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                });
            }

            //切换当前标签页
            state.editableTabsValue = tab.name;
        },
        // 改变路由状态
        changeHasRoute(state, hasRoute) {
            state.hasRoute = hasRoute
        },
        setMenuList(state, menus) {
            state.menuList = menus
        },
        setPermList(state, perms) {
            state.permList = perms
        },
        resetState: state => {
            // 标签页
            state.editableTabsValue = 'Index'
            state.editableTabs = [{
                title: '首页',
                name: 'Index'
            }]
            // 是否绑定过路由
            state.hasRoute = false
            // 菜单列表
            state.menuList = []
            // 权限列表
            state.permList = []
        }
    },
    actions: {}
}
